package fastwave.cloud.demo.fastwave.biz.subscriber.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>Title: HeadersConfig</p>
 * <p>Description: </p>
 *
 * @author: dwLiu
 * @date: 2020/4/6 23:41
 */
@Configuration
public class HeadersConfig {
    @Bean
    HeadersExchange HeadersExchange(){
        return new HeadersExchange("HeadersExchange");
    }

    /**
     * 队列
     * @return
     */
    @Bean
    Queue HeadersQueue1(){
        return new Queue("HeadersQueue1");
    }

    @Bean
    Queue HeadersQueue2(){
        return new Queue("HeadersQueue2");
    }

    @Bean
    Queue HeadersQueue3(){
        return new Queue("HeadersQueue3");
    }

    @Bean
    Queue HeadersQueue4(){
        return new Queue("HeadersQueue4");
    }

    /**
     * 交换机和队列绑定
     * @return
     */
    @Bean
    Binding BindHeaders1(){
        return BindingBuilder.bind(HeadersQueue1()).to(HeadersExchange()).whereAll("token","id").exist();
    }
    @Bean
    Binding BindHeaders2(){
        return BindingBuilder.bind(HeadersQueue1()).to(HeadersExchange()).whereAny("token","id").exist();
    }

    @Bean
    Binding BindHeaders3(){
        Map<String,Object> map = new HashMap<>();
        map.put("token","123");
        map.put("id","123");
        return BindingBuilder.bind(HeadersQueue1()).to(HeadersExchange()).whereAll(map).match();
    }

    @Bean
    Binding BindHeaders4(){
        Map<String,Object> map = new HashMap<>();
        map.put("token","123");
        map.put("id","123");
        return BindingBuilder.bind(HeadersQueue1()).to(HeadersExchange()).whereAny(map).match();
    }
}
